package com.bor.gb.core.repo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.repository.MongoRepository;

import javax.annotation.Nonnull;
import java.util.List;

/**
 * Created by bor on 11/8/14.
 */
public abstract class DataService<T>  {

    @Autowired
    private MongoRepository<T, String> repository;

    public T save(T entity){
        return repository.save(entity);
    }

    public void deleteAll() {
        repository.deleteAll();
    }

    public void delete(Iterable<? extends T> entities) {
        repository.delete(entities);
    }

    public void delete(T entity) {
        repository.delete(entity);
    }

    public void delete(String s) {
        repository.delete(s);
    }

    public long count() {
       return repository.count();
    }

    public Iterable<T> findAll(Iterable<String> strings) {
        return repository.findAll(strings);
    }

    public boolean exists(String s) {
        return repository.exists(s);
    }

    @Nonnull
    public T findOne(String s) {
        return findOne(s);
    }

    public <S extends T> List<S> save(Iterable<S> ses) {
        return repository.save(ses);
    }

    public List<T> findAll() {
        return repository.findAll();
    }

    public List<T> findAll(Sort orders) {
        return repository.findAll(orders);
    }

    @Nonnull
    public Page<T> findAll(Pageable pageable) {
        return findAll(pageable);
    }

}
